import { http } from "@/utils/http";
import { BindInfo, PageResponse } from "@/api/model/baseModel";
import { Role } from "@/api/model/roleModel";

enum Api {
  RoleList = "/role/list",
  RoleAll = "/role/all",
  SaveRole = "/role/save",
}

export function getRoleList(param: Role) {
  return http.get<PageResponse<Role>>({
    url: Api.RoleList,
    params: param,
  });
}
export function getRoleAll() {
  return http.get<Role[]>({
    url: Api.RoleAll,
  });
}

export function checkCode(code: string, id?: string) {
  return http.get<Boolean>({
    url: `/role/check/${code}`,
    params: { id },
  });
}

export function changeState(id: string, state: boolean) {
  return http.post<Boolean>({
    url: `/role/state/${id}/${state}`,
  });
}

export function saveRole(role: Role) {
  return http.post<Boolean>({
    url: Api.SaveRole,
    params: role,
  });
}

export function roleBindInfo(roleId: string) {
  return http.get<BindInfo<Role>>({
    url: `/role/bindInfo/${roleId}`,
  });
}

export function bindRole(roleId: string, roleIds: string[]) {
  console.log(roleIds);
  return http.post<Role[]>({
    url: `/role/bind/${roleId}`,
    params: { roleIds },
  });
}

export function unbindRole(roleId: string, roleIds: string[]) {
  console.log(roleIds);
  return http.post<Role[]>({
    url: `/role/unbind/${roleId}`,
    params: { roleIds },
  });
}

export function deleteRole(id: string) {
  return http.post<string>({
    url: `/role/deleteRole/${id}`,
  });
}
